Imports Security.Entities
Imports DataAccess.Base
Imports System.ComponentModel

Public Class RoleDAO
    Inherits TableDAO(Of Role)

    Public Sub New()
        Me.TableName = "Security_Roles"
        Me.IDColumn = "RoleId"
    End Sub

    <DataObjectMethod(DataObjectMethodType.Select)> _
    Public Function GetByApplication(ByVal appId As Guid) As IList(Of Role)
        Dim query As String = String.Format("SELECT * FROM {0}", Me.TableName)
        query &= String.Format(" WHERE ApplicationId = '{0}'", appId.ToString())
        Return GetByQuery(query)
    End Function

    <DataObjectMethod(DataObjectMethodType.Select)> _
    Public Function GetByGroup(ByVal groupId As Guid) As IList(Of Role)
        Dim query As String = String.Format("SELECT * FROM {0} WHERE RoleId IN ", Me.TableName)
        query &= String.Format("(SELECT RoleId FROM Security_RolesInGroup WHERE GroupId = '{0}')", groupId.ToString())
        Return GetByQuery(query)
    End Function
End Class
